'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: mcp_copy_handle.py
* @Time: 2025/11/21
* @All Rights Reserve By Brtc
'''
from mcp_core.mcp_client import MCPClient
from mcp_core.mcp_protocol import StatusCode


def example_copy_operation():
    print("Mcp Copy Operation!!")
    with MCPClient(host='127.0.0.1', port=8080) as client:
        print("首先创建上下文！")
        response = client.create_context(
            content={"data":"重要数据", "version":1},
            metadata={"labels":["important"], "scope":"user"},
            extensions={"backup":True}
        )

        if response.status_code != StatusCode.CREATED.value:
            print("创建失败！")

        source_id = response.data["context"]["id"]
        print("源上下文id: ", source_id)

        print("开始复制上下文！")
        target_id = "ctx_backup_001"
        response = client.copy_context(source_id, target_id)
        print("状态码:", response.status_code)
        print("消息:", response.message)

        if response.status_code == StatusCode.CREATED.value:
            print("已经成功复制到 id:", target_id)


        print("验证复制结果！")
        source_ctx = client.read_context(source_id)
        target_ctx = client.read_context(target_id)

        print(" 源内容:", source_ctx.data["context"]["content"])
        print(" 复制内容:", target_ctx.data["context"]["content"])


if __name__ == '__main__':
    example_copy_operation()